<?php
/**
 * LICENSE
 *
 * This source file is subject to the new BSD license that is bundled
 * with this package in the file license.txt or that can be found at 
 * http://code.google.com/p/billboardce/wiki/License.
 *
 * @package    Ot_Filter_Mac
 * @category   filter
 * @license    http://code.google.com/p/billboardce/wiki/License New BSD License
 * @version    SVN: $Id: $
 */

/**
 * Filters mac address.
 *
 * @package    Ot_Filter_Mac
 * @category   Filter
 */
class Ot_Filter_Mac implements Zend_Filter_Interface
{
    /**
     * delimiter between the numbers in the mac
     *
     * @var mixed
     */
    protected $_delimiter = ':';

    /**
     * Class constructor
     *
     *
     * @return void
     */
    public function __construct()
    {
    }

    /**
     * sets the delimiter
     *
     * @param mixed $delimiter
     */
    public function setDelimiter($delimiter)
    {
        $this->_delimiter = ':';
    }

    /**
     * Defined by Zend_Filter_Interface
     *
     * Returns the string $value, removing all but digit characters separated by $delimiter
     *
     * @param  string $value
     * @return string
     */
    public function filter($value)
    {
        $matches = array();
		preg_match_all('/([0-9a-fA-F]{2})[^0-9^a-f^A-F]*/', $value, $matches);

		$macArray = $matches[1];

		return strtoupper(implode($this->_delimiter, $macArray));
    }
}
